/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package android.abach;

import static android.R.attr.text;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import modele.DAO;
import modele.Medecin;

/**
 *
 * @author abach
 */
public class AutreActivity extends ListActivity {

    Button button;
    ImageView image;
    private EditText resultat;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle icicle) {

        super.onCreate(icicle);
        setContentView(R.layout.autrevue);

        //lecture des noms
        TextView label = (TextView) findViewById(R.id.label);
        Intent inter = getIntent();
        String num = inter.getStringExtra("leDep");

        //  label.setText(num);
        final List<Medecin> lesMedecins = DAO.getLesMedecins(num);
        MedAdapter adapter = new MedAdapter(lesMedecins, this);
        setListAdapter(adapter);

//on va créer le bouton
        Button button = (Button) findViewById(R.id.btnFiltrer);

        // on crée un écouteur qui fais gaffe si on touche au bouton
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                resultat = (EditText) findViewById(R.id.filtrage);
                String texte = resultat.getText().toString();
                List<Medecin> lesMedecinsFiltrer;
                lesMedecinsFiltrer = new ArrayList<Medecin>();
                for (Medecin unMed : lesMedecins) {
                    if (unMed.getNom().startsWith(texte)) {
                        lesMedecinsFiltrer.add(unMed);
                    }
                }
                // contexte de l'activité, la classe au dessus.
                MedAdapter adapter = new MedAdapter(lesMedecinsFiltrer, getApplicationContext());
                setListAdapter(adapter);

            } });
    }
            // onlistitemclick
            @Override
            protected void onListItemClick(ListView l, View v, int position, long id) {

                String tel = "tel:"+((Medecin)l.getItemAtPosition(position)).getTel();
                 
                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(tel));

                startActivity(intent);
            }

//         en cas de click sur le bouton
//        Toast.makeText(getApplicationContext(), "coucou",
//                Toast.LENGTH_LONG).show();
//

}
